const express = require('express');
const bodyParser = require('body-parser');
const userRouter = require('./user');
const app = express();


app.use('/static', express.static('files'))

app.use(function (req, res, next) {
  console.log('application middleware ..')
  next();
})

//extended: false 表示是否使用系统模块 querystring ,官方推荐
//extended: true 使用第三方qs来处理
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use('/user', userRouter)

//错误优先的原则
app.use(function (err, req, res, next) {
  console.log(err.stack);
  res.status(200).send('somting is wrong!')
})

app.listen(3000, () => {
  console.log('localhost start 3000 ...')
})